#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import scrapy as scrapy


class ChangeCustId(scrapy.Spider):
    name = "chanegCustId"
    custom_settings = {
        'ITEM_PIPELINES':{'ChangeCustIdPipeline':300},
    }

    def __init__(self,category=None,*args,**kwargs):
        super(ChangeCustId,self).__init__(*args,**kwargs)
        # channel = getattr(self,'channel',None)
        # custId = getattr(self,'custId',None)
        # self.start_urls = ['https://www.%s/gp/profile/%s/ref=cm_cr_dp_d_pdp?ie=UTF8' % (channel, custId), ]

    def start_requests(self):
        channel = getattr(self,'channel',None)
        custId = getattr(self,'custId',None)

        if channel is not None and custId is not None:
            url = 'https://www.%s/gp/profile/%s/ref=cm_cr_dp_d_pdp?ie=UTF8' % (channel,custId)
            print ("**********%s********************" % url)
            yield scrapy.Request(url,self.parse,
                                 headers={'User-Agent': "Mozilla/5.0 (X11; CrOS i686 2268.111.0) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11"}
                                 )


    def parse(self,response):
        print ("*****************************************************************")
        print (response.url)
